package com.eorchis.module.reply.ui.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eorchis.core.service.IBaseService;
import com.eorchis.core.ui.commond.ResultState;
import com.eorchis.core.ui.controller.AbstractBaseController;
import com.eorchis.module.reply.service.IReplyService;
import com.eorchis.module.reply.ui.commond.ReplyQueryCommond;
import com.eorchis.module.reply.ui.commond.ReplyValidCommond;
import com.eorchis.utils.utils.PropertyUtil;

/**
 * Title: ReplyController<br>
 * Description: 消息回复表管理控制器<br>
 * Company: GoldGov<br>
 * Copyright @ 2012 GoldGov .All rights reserved.<br>
 * @author RongSL
 * @createDate 2016-05-06
 * @version $Revision$
 */
@Controller("replyController")
@RequestMapping(value = ReplyController.MODULE_PATH)
public class ReplyController extends AbstractBaseController<ReplyValidCommond,ReplyQueryCommond> {
	// 模块页面根路径
	public static final String MODULE_PATH = "/module/reply";
	// 消息回复表接口
	@Resource(name = "com.eorchis.module.reply.service.impl.ReplyServiceImpl")
	private IReplyService replyService;
	
	@Override
	public IBaseService getService() {
		return replyService;
	}

	@Override
	public String getModulePath() {
		return MODULE_PATH;
	}
	/**
	 * 查看单个回复
	 * @param commond
	 * @param request
	 * @param response
	 * @param resultState
	 * @return
	 * @throws Exception
	 * @author NingSS
	 * @date 2016-5-11
	 */
	@RequestMapping("/findReply")
	public String findReply(@ModelAttribute("data")ReplyValidCommond commond,
			HttpServletRequest request,HttpServletResponse response,
			@ModelAttribute("resultState") ResultState resultState)
			throws Exception {	
		resultState.setState(ResultState.RESULT_STATE_SUCCESS);
		if(PropertyUtil.objectNotEmpty(commond.getReplyId())){
			ReplyValidCommond result = replyService.find(commond.getReplyId());
			commond.setReplyValue(result.getReplyValue());
		}else{
			resultState.setMessage("请点击想要查看的回复!");
			resultState.setState(ResultState.RESULT_STATE_FAIL);
		}
		return "";
	}
}
